<?php
class Exts_Paginator extends Zend_Paginator
{
    /**
     * Inicia un paginador con la configuracion correspondiente
     * 
     * @adapter Mixed Objeto que contiene el contenido a paginar
     * @page Int NUmero de la pagina Actual
     * @view Zend_View 
     * @tpl String Nombre del template
     */
    public function __construct( $adapter, $page = NULL, $view = NULL,  $tpl = '' )
    {
        if( Zend_Registry::isRegistered('config') ) {
            $config = Zend_Registry::get( 'config' );
            $ipp = $config->paginado->item->perpage;
            $template = $config->paginado->template;
        } else {
            $ipp = 20;
        }

        
        if( !empty( $tpl )) {
            $template = $tpl;
        } elseif( !isset( $template )) {
        	$template = 'paginator/search_paginator_control.phtml';
        }
        
    	Zend_Paginator::setDefaultScrollingStyle( 'all' );
        Zend_View_Helper_PaginationControl::setDefaultViewPartial( $template );

        if ( $adapter instanceof Zend_Db_Select ) {
			parent::__construct( new Zend_Paginator_Adapter_DbSelect( $adapter ) );
        } elseif ( $adapter instanceof Zend_Db_Table_Rowset ) {
            parent::__construct( new Zend_Paginator_Adapter_Iterator( $adapter ) );
        } else {
       		parent::__construct( $adapter );
        }
        if( ! empty( $view )) {
            $this->setView($view);
        }

        $this->setItemCountPerPage( $ipp );
       	$this->setCurrentPageNumber( $page	);
        
	}
}
